<template>
    <div class="photoinfo-container">
        <h3>{{photoinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间:{{photoinfo.addtime|dateFormat}}</span>
            <span>点击:{{photoinfo.click}}次</span>
        </p>

        <hr>

        <!--缩略图区域-->
        <div class="thumbs">
            <img class="preview-img" v-for="item in thumbImgList" :src="item.img_url" 
            height="100" width="100" @click="$preview.open(item.img_url)" :key="item.img_url"><!-- 
            <vue-preview :slides="thumbImgList" :src="this.thumbImgList.img_url"></vue-preview> -->
        </div>

        <!--图片内容区域-->
        <div class="content" v-html="photoinfo.content"></div>
            <!--放置评论组件-->
        <cmt-box :id="this.id"></cmt-box>
        
    </div>
</template>
<script>
//导入评论子组件
import comment from '../subcomponents/comment.vue';
import {Toast} from "mint-ui";
export default{
    data(){
        return{
            id:this.$route.params.id,  //从路由中获去到图片的id
            photoinfo:{},//图片详情
            thumbImgList: [] // 缩略图的数组
       };
    },
    created(){
        this.getPhotoInfo();
        this.getThumbs();
    },
    methods:{
        getPhotoInfo(){
            //获取图片的详情
            this.$http.get('PhotoInfo/' +this.id).then(result =>{
                if(result.body.code === 0){
                    this.photoinfo = result.body.data;
                }else{
                    Toast("获取分类失败");
                }
            });
        },
        getThumbs(){
            this.$http.get('previewImg/' +this.id).then(result =>{

                if(result.body.code === 0){
                    //循环每个图片数据，补全图片的宽和高
                    result.body.data.forEach(item=>{ 
                        item.w = 200;
                        item.h = 200; 
                        item.msrc = item.img_url;
                    });
                    //把完成的数据保存到list中
                    this.thumbImgList = result.body.data; 
                    console.log(this.thumbImgList);
                }
            });
        }
    },
    components:{    //注册子组件
        "cmt-box" : comment
    }
}
</script>
<style lang="scss" scoped>
.photoinfo-container{
    padding: 3px;
    h3{
        color:#26A2FF;
        font-size:15px;
        text-align:center;
        margin:15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size:13px;
    }
    .content{
        font-size:13px;
        line-height:30px;
    }
    .thumbs{
        img{
            margin: 6px;
            box-shadow: 0 0 8px #999;
        }
    }
}
</style>




